import keyboard
from playsound import playsound
import threading
import os
import random

# 播放声音
def play(keysound):
    playsound('./keysound/' +  keysound)

# 按下键盘
def Press(x):
    if x.event_type == 'down':
      match x.name:
        case 'j':
          threading.Thread(target=play,args=('j.mp3',)).start()
        case 'n':
          threading.Thread(target=play,args=('n.mp3',)).start()
        case 't':
          threading.Thread(target=play,args=('t.mp3',)).start()
        case 'm':
          threading.Thread(target=play,args=('m.mp3',)).start()
        case 'h':
          threading.Thread(target=play,args=('h.mp3',)).start()
        case 'a':
          threading.Thread(target=play,args=('a1.mp3',)).start()
        case 'e':
          threading.Thread(target=play,args=('a2.mp3',)).start()
# 入口函数
if __name__ == '__main__':
    keyboard.hook(Press)
    keyboard.wait()
  


